package com.yaolisheng.reporter;

import com.alibaba.fastjson2.JSON;
import com.yaolisheng.entity.gt3.DialTestData;
import com.yaolisheng.entity.gt3.Gt3DialTestData;
import com.yaolisheng.utils.FileUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.Collectors;

/**
 * @author : yaols
 * Desc:
 * Date: 2022.12.14.11:13
 **/

@Slf4j
@Configuration
@EnableScheduling
public class G3DialTestDataReporter {
    private static final String dialTestMockDataFile = "Gt3/bc_zongju.json";


    private static List<DialTestData> sendJsonList = new ArrayList<>();
    private static Map<String, String> distCodeMap;

    static {
        String content = FileUtils.readTextFileAsResource(dialTestMockDataFile);
        sendJsonList = JSON.parseArray(content, DialTestData.class);
        distCodeMap =new HashMap<>();
        distCodeMap.put("00000000000", "国家税务总局");
        distCodeMap.put("13502000000", "厦门市税务局");
        distCodeMap.put("11500000000", "内蒙古自治区税务局");
        distCodeMap.put("15100000000", "四川省税务局");
        distCodeMap.put("13100000000", "上海市税务局");
        distCodeMap.put("14400000000", "广东省税务局");
    }

//    @Scheduled(fixedRate = 100000 * 1000)
    public void checkReporter() {
        Map<String, List<DialTestData>> collect = sendJsonList.stream().collect(Collectors.groupingBy(DialTestData::getDistCode));
        System.out.println(collect.size());
        collect.forEach((k, v) -> {
            System.out.println(k+"::"+distCodeMap.get(k));
        });

        collect.forEach((k,v) -> {
            System.out.println(distCodeMap.get(k));
            v.forEach(data -> {
                Map<String, List<Gt3DialTestData>> collect1 = data.getDatas().stream().collect(Collectors.groupingBy(Gt3DialTestData::getApplicationName));
                collect1.forEach((key,value) -> {
                    System.out.println("\t"+key);
                });
            });
        });
        AtomicLong counter = new AtomicLong();
        sendJsonList.forEach(sendJson -> counter.set(counter.get() + sendJson.getDatas().size()));
        System.out.println(counter.get());
    }
}
